package main

import (
	"github.com/gin-contrib/cors"
	"github.com/gin-gonic/gin"
	api "hais.pw/shorturl/apis"
	db "hais.pw/shorturl/database"
	. "hais.pw/shorturl/models"
)

func initRouter() *gin.Engine {
	//gin.SetMode(gin.ReleaseMode)
	c := gin.Default()
	c.Use(cors.Default())

	//短链接
	db.Exectue.AutoMigrate(&Link{})
	c.POST("/link", api.LinkAddApi)
	c.GET("/:tag", api.LinkToByShort)
	c.GET("/", api.GoToHome)
	c.POST("/link/:short", api.LinkFindByShort)

	return c
}
